-
-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement thread creation deletion event callback. #506
base: main
Are you sure you want to change the base?
Conversation
4b21fc5
to
39a39d4
Compare
494cc56
to
09a55f2
Compare
This would be useful |
I know, and since I felt like others would also want it i decided to open a pull request. |
Thanks for the PR, I'll review it soon |
40a8676
to
e84bce1
Compare
if self.unlikely_memory_error() { | ||
ffi::lua_pushthread(ref_thread) | ||
} else { | ||
protect_lua!(ref_thread, 0, 1, |ref_thread| ffi::lua_pushthread(ref_thread))? | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lua_pushthread
does not trigger longjmp
let main_extra = ExtraData::get(main_state); | ||
let main_raw_lua: &RawLua = (*main_extra).raw_lua(); | ||
let _guard = StateGuard::new(main_raw_lua, state); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RawLua
is singleton, it never changes (as well as ExtraData
instance)
@@ -556,6 +559,21 @@ impl RawLua { | |||
value.push_into_stack(self) | |||
} | |||
|
|||
pub(crate) unsafe fn push_ref_thread(&self, ref_thread: *mut ffi::lua_State) -> Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref_thread
seems misleading name here, it cannot be the reference thread (as it's a very special type of thread used internally)
unsafe extern "C-unwind" fn userthread_proc(parent: *mut ffi::lua_State, state: *mut ffi::lua_State) { | ||
callback_error_ext(state, ptr::null_mut(), move |extra, _| { | ||
let raw_lua: &RawLua = (*extra).raw_lua(); | ||
let _guard = StateGuard::new(raw_lua, state); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, why we need to switch state here?
let userthread_cb = | ||
mlua_expect!(userthread_cb, "no userthread callback set in userthread_proc"); | ||
if parent.is_null() { | ||
raw_lua.push(Value::Nil).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems this stack value is never used ?
let _guard = StateGuard::new(main_raw_lua, state); | ||
userthread_cb((*main_extra).lua(), event_info) | ||
} else { | ||
raw_lua.push_ref_thread(parent).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
push parent two times?
/// When a thread is created, it contains the thread that created it. | ||
Created(Thread), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be vice versa? The thread that was created, not parent.
No description provided.